home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / daemons / nfs / nfs-serv.2be / nfs-serv / nfs-server-2.2beta16 / rename.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-21  |  1.3 KB  |  59 lines

  1. /* rename.c -- rename a file
  2.    Copyright (C) 1988, 1992 Free Software Foundation
  3.  
  4. This file is part of GNU Tar.
  5.  
  6. GNU Tar is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Tar is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Tar; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #ifdef HAVE_CONFIG_H
  21. #include <config.h>
  22. #endif
  23.  
  24. #include <sys/stat.h>
  25. #include <errno.h>
  26. #ifndef
  27. #ifndef STD_HEADERS
  28. extern int errno;
  29. #endif
  30.  
  31. /* Rename file FROM to file TO.
  32.    Return 0 if successful, -1 if not. */
  33.  
  34. int
  35. rename (from, to)
  36.      char *from;
  37.      char *to;
  38. {
  39.   struct stat from_stats;
  40.  
  41.   if (stat (from, &from_stats))
  42.     return -1;
  43.  
  44.   if (unlink (to) && errno != ENOENT)
  45.     return -1;
  46.  
  47.   if (link (from, to))
  48.     return -1;
  49.  
  50.   if (unlink (from) && errno != ENOENT)
  51.     {
  52.       unlink (to);
  53.       return -1;
  54.     }
  55.  
  56.   return 0;
  57. }
  58.  
  59.